# from fdfs_client.client import Fdfs_client, get_tracker_conf
#
#
# client_conf = get_tracker_conf(r'G:\work\vuework\crash-handler-management\pythonManger\util\client.conf')
# client = Fdfs_client(client_conf)
# ret = client.upload_by_filename(r'D://12.jpg')
import random
from urllib import request
import numpy as np
from fdfs_client.client import Fdfs_client, get_tracker_conf

# try:
#   tracker_path = get_tracker_conf('./client.conf')
#   client = Fdfs_client(tracker_path)
#   # ret_upload
#   # ret_upload = client.upload_by_filename('D://12.jpg') # 图片地址
#   resp = request.urlopen("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2797486824,1669366989&fm=26&gp=0.jpg")
#   # image = np.asarray(bytearray(resp.read()), dtype="uint8")
#   ret_upload = client.upload_by_buffer(resp.read()) # 图片地址
#   # print(ret_upload['Remote file_id'])
#   print(ret_upload)
# except Exception as e:
#   print('连接失败', e)


def uploadPic(picurl):
  try:
    tracker_path = get_tracker_conf('./client.conf')
    client = Fdfs_client(tracker_path)
    # ret_upload
    # ret_upload = client.upload_by_filename('D://12.jpg') # 图片地址
    # resp = request.urlopen("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2797486824,1669366989&fm=26&gp=0.jpg")
    resp = request.urlopen(picurl)
    # image = np.asarray(bytearray(resp.read()), dtype="uint8")
    ret_upload = client.upload_by_buffer(resp.read()) # 图片地址
    # print(ret_upload['Remote file_id'])
    # print(ret_upload)
    return ret_upload['Remote file_id']
  except Exception as e:
    print('连接失败', e)


if __name__ == '__main__':
  print(random.randint(0,9))
